#pragma once
#include "IOCPAsynConnectionSocket.h"
#include <string>
#include <map>
#include <sstream>

class CIOCPConnectionPool
{
public:
	CIOCPConnectionPool();
	~CIOCPConnectionPool(void);

	bool Create(CIOCPModel* _pIOCP);
	void Close();

	bool InsertConnection(const std::string &_strIP, int _nPort, CIOCPAsynConnectionSocket* _pConnection);
	void RemoveConnection(const std::string &_strIP, int _nPort){
		std::ostringstream out;
		out<<_strIP;
		out<<":";
		out<<_nPort;
		std::string strConnectionName = out.str();

		std::map<std::string,CIOCPAsynConnectionSocket*>::iterator  iter = m_mapConnection.find(strConnectionName);

		if (iter != m_mapConnection.end())
		{
			m_mapConnection.erase(iter);
		}

	}
	CIOCPAsynConnectionSocket* GetConnection(const std::string &_strIP, int _nPort);

private:
	CIOCPModel* m_pMainIOCP;
	std::map<std::string,CIOCPAsynConnectionSocket*> m_mapConnection;
};
